package com.yeyks.appcontroller;

import com.yeyks.dal.domain.UserInfo;
import com.yeyks.dto.UserAccountOverviewDTO;
import com.yeyks.model.Ajax.AjaxResponseBody;
import com.yeyks.service.UserAccountOverviewService;
import com.yeyks.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fuchangshuai
 * @date 2019/4/26 0026
 */
@Api(tags = "用户账户接口", description = "用户账户")
@Slf4j
@RestController
@RequestMapping(value = "/app/account")
public class UserAccountOverviewController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private UserAccountOverviewService accountService;

    /**
     * 获取用户账户信息
     *
     * @param token
     * @return
     */
    @ApiOperation(value = "获取用户账户信息", notes = "获取用户账户信息", response = UserAccountOverviewDTO.class)
    @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String")
    @PostMapping(value = "/info")
    public ResponseEntity<?> info(@RequestParam(name = "token") String token) {
        UserInfo userInfo = userInfoService.tokenUserInfo(token);
        UserAccountOverviewDTO accountOverviewDTO = accountService.info(userInfo);
        return ResponseEntity.ok(AjaxResponseBody.success(accountOverviewDTO));
    }

}
